function [VAR,VARChol,VARbs,VARCholbs]=BA_doVAR(VAR,DATASET_VAR,DATASET_FACTORS,nboot,clevel)
% Code based on Gertler and Karadi (2015)

% VAR specification
%%%%%%%%%%%%%%%%%%%%

% Setup
VAR.vars             = DATASET_VAR.TSERIES(VAR.smpl_min_VAR:VAR.smpl_max_VAR,cell2mat(values(DATASET_VAR.MAP,VAR.select_vars)));
VAR.proxies          = DATASET_FACTORS.TSERIES(VAR.smpl_min_FACTORS:VAR.smpl_max_FACTORS,cell2mat(values(DATASET_FACTORS.MAP,VAR.select_factors)));
VAR.T                = length(VAR.vars)-VAR.p;
VAR.n                = size(VAR.vars,2);
[VAR.T_m,VAR.T_n]    = size(VAR.proxies);
VAR.T_m_end          = VAR.smpl_max_VAR-VAR.smpl_max_VAR_factors;      % The difference between where the VAR and the factors end in the VAR sample
VAR.year             = DATASET_VAR.TSERIES(VAR.smpl_min_VAR:VAR.smpl_max_VAR,cell2mat(values(DATASET_VAR.MAP,{'YEAR'})));
VAR.month            = DATASET_VAR.TSERIES(VAR.smpl_min_VAR:VAR.smpl_max_VAR,cell2mat(values(DATASET_VAR.MAP,{'MONTH'})));

% Structural Estimation
VAR 			= AB_doProxySVAR_single(VAR);
VARbs 			= AC_doProxySVARbootstrap_single(VAR,nboot,clevel);

% Cholesky Approach
VARChol 		= VAR;
VARChol.vars 	= VAR.vars(:,VAR.chol_order); % reorder in decreasing order of exogeneity (lower triangle)
VARChol 		= AD_doCholSVAR_single(VARChol);
VARCholbs 		= AE_doCholSVARbootstrap_single(VARChol,nboot,clevel);
